{include file="public/_meta" /}
<body>
<style>
    .required_b{
        color: red;
    }
    /*
*自定义的checkbox
*/

    /*设置复选框描述文字为相对定位，因为下面要在此label下面设置两个伪类，基于它进行定位。*/
    label.checkbox_label {
        position: relative;
        display: inline-block;
        padding: 2px 9px;
        -webkit-user-select: none;
        user-select: none; /*禁止选中label中的文字，因为勾选时双击了很容易选中*/
    }
    /*隐藏原生的input复选框*/
    .my_checkbox {
        opacity: 0;
    }
    /*after伪类生成固定大小的选框，边框颜色设置为灰色，定位到隐藏的checkbox位置上*/
    label.checkbox_label::after {
        content: "";
        display: block;
        width: 15px;
        height: 15px;
        border: 1px solid #d9d9d9;
        border-radius: 2px;
        background-color: #fff;
        position: absolute;
        top: 4px;
        left: -15px;
        z-index: 1;
        cursor: pointer;
        -webkit-transition: all .2s;
        transition: all .2s;
    }
    /*原生checkbox hover时，此时自定义的伪类选框边框颜色变化为蓝色*/
    .my_checkbox:hover+label.checkbox_label::after {
        border-color: #1890ff;
    }
    /*原生的checkbox选中后，对应的自定义选框添加边框颜色和背景颜色*/
    .my_checkbox:checked+label.checkbox_label::after {
        border-color: #1890ff;
        background-color: #1890ff;
    }
    /*生的checkbox选中后，由于自定义的选框背景为纯色，故这里又定义了一个before伪类来模拟勾选的对勾，这里用一个盒子的边框模拟对勾选中符号*/
    .my_checkbox:checked+label.checkbox_label::before {
        content: "";
        display: block;
        width: 6px;
        height: 10px;
        border-bottom: 2px solid #fff;
        background-color: #1890ff;
        border-right: 2px solid #fff;
        transform: rotate(45deg);
        position: absolute;
        top: 5px;
        left: -10px;
        z-index: 2;
        box-sizing: border-box;
    }
</style>
<div class="wrapper">

    {include file="public/_header" /}

    <!-- Sidebar -->
    {include file="public/_menu" /}
    <!-- End Sidebar -->

    <div class="main-panel">

        <div class="content">
            <div class="page-inner">

                <!-- 面包屑 -->
                {include file="public/_page_header" /}

                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header">
                                <div class="d-flex align-items-center">
                                    <h4 class="card-title">消息列表</h4>
                                    {if condition="in_array($group_id,[1])"}
                                    <button class="btn btn-primary btn-round ml-auto" data-toggle="modal" data-target="#addRowModal" onClick="add_item(0)">
                                        <i class="fa fa-plus"></i>
                                        添加
                                    </button>
                                    {/if}
                                </div>

                                <form class="row">

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <select class="form-control" name="msg_type">
                                                <option value="">全部类型</option>
                                                {volist name="msglist" id="vo"}
                                                <option value={$key} {if condition="1 eq $msg_type"}selected{/if}>{$vo}</option>
                                                {/volist}
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="username" value="{$username}" placeholder="商户账号">
                                        </div>
                                    </div>


                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="mer_name" value="{$mer_name}" placeholder="商户名称">
                                        </div>
                                    </div>

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="mer_desc" value="{$mer_desc}" placeholder="商户简称">
                                        </div>
                                    </div>

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="phone" value="{$phone}" placeholder="联系电话">
                                        </div>
                                    </div>


                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <select class="form-control" name="status">
                                                <option value="">全部状态</option>
                                                <option value="0" {if condition="1 eq $status"}selected{/if}>未读</option>
                                                <option value="1" {if condition="2 eq $status"}selected{/if}>已读</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="times" id="times" value="{$times}" placeholder="创建时间" autocomplete="off">
                                        </div>
                                    </div>


                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <button type="submit" class="btn btn-primary">查询</button>
                                            <a href="{:url('Message/merchant')}" class="btn btn-info" style="color: white;position: absolute;left: 110px;">重置</a>
                                        </div>
                                    </div>

                                </form>

                            </div>


                            <div class="card-body">
                                <!-- Modal -->
                                <div class="modal fade" id="addRowModal" tabindex="-1" role="dialog" aria-hidden="true">
                                    <div class="modal-dialog" role="document">
                                        <div class="modal-content" style="width: 600px;">
                                            <div class="modal-header no-bd">
                                                <h5 class="modal-title">
                                                    <span class="fw-mediumbold">添加</span>

                                                </h5>
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                    <span aria-hidden="true">&times;</span>
                                                </button>
                                            </div>
                                            <div class="modal-body">
                                                <form id="form-modal">
                                                    <div class="row">

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="msg_type" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">消息类型</font></label>
                                                            <input type="checkbox" id="my_checkbox1" name="msg_type[1]" class="my_checkbox">
                                                            <label for="my_checkbox1" class="checkbox_label">系统消息</label>
                                                            <input type="checkbox" id="my_checkbox2" name="msg_type[2]" class="my_checkbox">
                                                            <label for="my_checkbox2" class="checkbox_label">右下角弹窗</label>
                                                            <input type="checkbox" id="my_checkbox3" name="msg_type[3]" class="my_checkbox">
                                                            <label for="my_checkbox3" class="checkbox_label">居中强弹窗</label>
                                                            <input type="checkbox" id="my_checkbox4" name="msg_type[4]" class="my_checkbox">
                                                            <label for="my_checkbox4" class="checkbox_label">短信消息</label>

                                                        </div>
                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="admin_user" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">接收商户</font></label>
                                                            <div class="col-md-8 p-0" id="demo1">

                                                            </div>
                                                        </div>
                                                        <div class="form-group form-inline col-md-12" id="charge_price">
                                                            <label for="title" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">标题</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="title" name="title" placeholder="标题">
                                                            </div>
                                                        </div>


                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="remark" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">备注</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <textarea id="content" name="content" class="form-control input-full" style="height: 200px!important"></textarea>
                                                            </div>
                                                        </div>



                                                    </div>
                                                    <div class="modal-footer no-bd">
                                                        <input type="hidden" id="id" name="id" value="">
                                                        <button type="submit" id="addRowButton" class="btn btn-primary">保存</button>
                                                        <button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>
                                                    </div>
                                                </form>
                                            </div>

                                        </div>
                                    </div>
                                </div>

                                <div class="table-responsive">
                                    <table id="add-row" class="display table table-striped table-hover" >
                                        <thead>
                                        <tr>
                                            <th><input type="checkbox" class="check">全选</th>
                                            <th>ID</th>

                                            <th>消息类型</th>
                                            <th>接收商户</th>
                                            <th>联系电话</th>
                                            <th>标题</th>
                                            <th>内容</th>
                                            <th>状态</th>
                                            <th>时间</th>

                                            <th style="width: 10%">操作</th>


                                        </tr>
                                        </thead>

                                        <tbody>

                                        {volist name="infos" id="vo"}
                                        <tr>
                                            <td><input type="checkbox" class="check" value="{$vo.id}" name="idcheckbox"></td>
                                            <td>{$vo.id}</td>

                                            <td>{$vo.msg_type}</td>

                                            <td>
                                                账号：{$vo.username}
                                                <br>
                                                商户名：{$vo.mer_name}<br>
                                                商户简称：{$vo.mer_desc}
                                            </td>

                                            <td>{$vo.phone}</td>
                                            <td>{$vo.title}</td>
                                            <td>{$vo.content}</td>
                                            <td>{$vo.status|getMsgStatus}</td>

                                            <td>创建时间：{$vo.create_time}<br>
                                                修改时间：{$vo.update_time}
                                            </td>

                                            <td>
                                                <div class="form-button-action">



                                                    {if condition="$vo.status eq 1"}

<!--                                                    <button type="button" data-toggle="tooltip" title="" onClick="admin_stop(this,'{$vo.id}')" class="btn btn-link btn-warning" data-original-title="停用">-->
<!--                                                        <i class="fa fa-toggle-on"></i>停用-->
<!--                                                    </button>-->


                                                    {else/}

                                                    <button type="button" data-toggle="tooltip" title="" onClick="admin_start(this,'{$vo.id}')" class="btn btn-link btn-success" data-original-title="标记已读">
                                                        <i class="fa fa-toggle-off"></i>标记已读
                                                    </button>
                                                    {/if}

<!--                                                    <button type="button" title="编辑" class="btn btn-link btn-primary btn-lg" data-toggle="modal" data-target="#addRowModal" onClick="edit_item('{$vo.id}')">-->
<!--                                                        <i class="fa fa-edit"></i>编辑-->
<!--                                                    </button>-->


                                                    <button type="button" data-toggle="tooltip" onClick="admin_del(this,'{$vo.id}')" title="" class="btn btn-link btn-danger" data-original-title="删除">
                                                        <i class="fa fa-times"></i>删除
                                                    </button>

                                                </div>

                                            </td>

                                        </tr>
                                        {/volist}

                                        </tbody>
                                    </table>

                                    <!-- 分页 (调取通用方法)-->
                                     <div class="layui-box layui-laypage layui-laypage-molv">{:pagination($infos)}</div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>


            </div>
        </div>

        {include file="public/_footer" /}


    </div>



</div>

{include file="public/_js" /}

</body>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    var SCOPE = {
        'status_url':"{:url('Message/status')}",
        'merstatus':"{:url('push/merstatus')}",
        'delete_url':"{:url('Message/delete')}",
        'item_url':"{:url('push/edit')}",
        'add_url':"{:url('Message/save2')}",
        'clue_url':"{:url('push/clue_url')}",
        'city_url':"{:url('clue/getRegion')}",
        'add_timing_url2':"{:url('push/save_timing2')}",
        'add_timeday2':"{:url('push/save_timeday2')}",
    };

    function loadRegion(sel,type_id,selName){
        $("#"+selName+" option").each(function(){
            $(this).remove();
        });
        $("<option value=0>请选择</option>").appendTo($("#"+selName));
        if($("#"+sel).val()==0){
            return;
        }
        $.post(SCOPE.city_url,{pid:$("#"+sel).val(),type:type_id},
            function(data){
                if(data.code == 1001){
                    $.each(data.data,function(idx,item){
                        $("<option value="+item.id+">"+item.name+"</option>").appendTo($("#"+selName));
                    });
                }else{
                    $("<option value='0'>请选择</option>").appendTo($("#"+selName));
                }
            }
        );
    }


    $(function(){

        var commitStatus = false;
        /*表单验证*/
        $("#form-modal").validate({
            rules:{

                admin_id:{
                    required:true,

                },
                title:{
                    required:true,

                },
                content:{
                    required:true,

                }

            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var url = SCOPE.add_url;
                if(commitStatus==true){
                    return false;
                }

                /*表单提交*/
                $(form).ajaxSubmit({
                    type: 'post',
                    url: url,
                    success: function(data){
                        if(data.code == 1001){
                            commitStatus = true;
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                parent.location.reload();
                            });
                        }else if(data.code==3011){
                            layer.confirm(data.msg,function(index){
                                $(form).ajaxSubmit({
                                    type: 'post',
                                    url: url,
                                    data:{is_pro_price:1},
                                    success: function(data){
                                        if(data.code == 1001){
                                            commitStatus = true;
                                            layer.msg(data.msg, {
                                                icon: 1,
                                                time: 2000
                                            }, function(){
                                                parent.location.reload();
                                            });
                                        }else{
                                            layer.msg(data.msg,{icon:2,time:2000});
                                        }
                                    },
                                    error: function(XmlHttpRequest, textStatus, errorThrown){
                                        layer.msg(errorThrown,{icon:2,time:2000});
                                    }
                                });
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:2000});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg(errorThrown,{icon:2,time:2000});
                    }
                });

            }
        });

        $("#form-modal4").validate({
            rules:{
                start_time2:{
                    required:true
                },
                end_time2:{
                    required:true
                }

            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var url = SCOPE.add_timing_url2;
                if(commitStatus==true){
                    return false;
                }
                var chk_value =[];
                $('input[name="idcheckbox"]:checked').each(function(){ //遍历，将所有选中的值放到数组中
                    chk_value.push($(this).val());
                });
                /*表单提交*/
                $(form).ajaxSubmit({
                    type: 'post',
                    url: url,
                    data:{id:chk_value},
                    success: function(data){
                        if(data.code == 1001){
                            commitStatus = true;
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                parent.location.reload();
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:2000});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg(errorThrown,{icon:2,time:2000});
                    }
                });

            }
        });

        $("#form-modal6").validate({
            rules:{

            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var url = SCOPE.add_timeday2;
                if(commitStatus==true){
                    return false;
                }
                var chk_value =[];
                $('input[name="idcheckbox"]:checked').each(function(){ //遍历，将所有选中的值放到数组中
                    chk_value.push($(this).val());
                });
                /*表单提交*/
                $(form).ajaxSubmit({
                    type: 'post',
                    url: url,
                    data:{id:chk_value},
                    success: function(data){
                        if(data.code == 1001){
                            commitStatus = true;
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                parent.location.reload();
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:2000});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg(errorThrown,{icon:2,time:2000});
                    }
                });

            }
        });

    });

    function add_item(id) {
        // document.getElementById('form-modal').reset();
        //
        //
        //
        // $("#city").children().remove();
        // $("<option value='0'>请选择</option>").appendTo($("#city"));
        $(".fw-mediumbold").text('添加');
        // var charge_type = $("#charge_type").val();
        //
        // if(charge_type == 1){
        //     $("#charge_price").hide();
        // }else{
        //     $("#charge_price").show();
        // }
    }

    function edit_item(id) {
        document.getElementById('form-modal').reset();

        $.each($("[name='weekdayd']"),function (i,val){
            // console.log($(this))
            val.style.display = 'none';
        });

        // var t1 = document.getElementById('push_type1');//选取id为test的元素
        // var t2 = document.getElementById('push_type2');//选取id为test的元素
        //
        // t1.style.visibility = 'hidden';// 隐藏元素
        //
        // t2.style.visibility = 'hidden';// 显示元素


        $("#charge_type").attr('disabled',true);
        $("#channel_id").multipleSelect('refresh');
        $("#account_id").multipleSelect('refresh');
        $("#week_time").multipleSelect('refresh');
        $.ajax({
            type: 'GET',
            url: SCOPE.item_url,
            dataType: 'json',
            data: {id:id},
            success: function(res){

                if(res.code == 1001){
                    $("#id").val(res.data.id);
                    $("#pro_id").val(res.data.pro_id);
                    $("#type").val(res.data.type);
                    // $("#channel_id").val(res.data.channel_id);
                    $("#mer_id").val(res.data.mer_id);
                    $("#province").val(res.data.prov);
                    if(res.data.city != ''){
                        $("#city").children().remove();
                        $("<option value='"+res.data.city+"'>"+res.data.city_name+"</option>").appendTo($("#city"));
                    }
                    $("#up_limit").val(res.data.up_limit);
                    $("#charge_type").val(res.data.charge_type);
                    $("#price").val(res.data.price);
                    $("#timing_time").val(res.data.timing_time);
                    $(":radio[name='status'][value='"+res.data.status+"']").prop("checked","checked");


                    var weekJson=JSON.parse(res.data.week_json);
                    $.each(weekJson,function (i,v){
                        $("#weekday"+i).val(v);
                    });

                    var charge_type = $("#charge_type").val();

                    if(charge_type == 1){
                        $("#charge_price").hide();
                    }else{
                        $("#charge_price").show();
                    }

                    var sceneIdList =res.data.channel_id.toString() ;


                    sceneIdArr = sceneIdList.split(",");


                    $('#channel_id option').each(function (i, content) {

                        if ($.inArray($.trim(content.value), sceneIdArr) >= 0) {

                            this.selected = true;

                        }else{
                            this.selected = false;
                        }

                    });
                    //加载完勾选项后也要刷新
                    $("#channel_id").multipleSelect('refresh');

                    //账户
                    var sceneIdList =res.data.account_id.toString() ;


                    sceneIdArr = sceneIdList.split(",");


                    $('#account_id option').each(function (i, content) {

                        if ($.inArray($.trim(content.value), sceneIdArr) >= 0) {

                            this.selected = true;

                        }else{
                            this.selected = false;
                        }

                    });
                    //加载完勾选项后也要刷新
                    $("#account_id").multipleSelect('refresh');

                    // if(res.data.type==1){
                    //     t2.style.visibility = 'hidden';// 隐藏元素
                    //
                    //     t1.style.visibility = 'visible';// 显示元素
                    // }else if(res.data.type==2){
                    //     t1.style.visibility = 'hidden';// 隐藏元素
                    //
                    //     t2.style.visibility = 'visible';// 显示元素
                    // }else{
                    //     t1.style.visibility = 'hidden';// 隐藏元素
                    //     t2.style.visibility = 'hidden';// 隐藏元素
                    // }



                    var sceneIdList =res.data.week_time.toString() ;


                    sceneIdArr = sceneIdList.split(",");


                    $('#week_time option').each(function (i, content) {

                        if ($.inArray($.trim(content.value), sceneIdArr) >= 0) {

                            this.selected = true;

                            var timeweek=$("#weekday"+content.value).parent().parent()[0];
                            timeweek.style.display = 'inline-block';

                        }else{
                            this.selected = false;
                        }

                    });
                    $("#week_time").multipleSelect('refresh');


                }else{
                    layer.msg(res.msg,{icon:2,time:2000});
                }

            },
            error:function(res) {
                layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
            }
        });
    }

    /*删除*/
    function admin_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                url: SCOPE.delete_url,
                dataType: 'json',
                data: {id:id},
                success: function(data){
                    if(data.code == 1001){
                        $(obj).parents("tr").remove();
                        layer.msg('删除成功!',{icon:1,time:2000});
                    }else{
                        layer.msg(data.msg,{icon:2,time:2000});
                    }

                },
                error:function(data) {
                    layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
                }
            });
        });
    }


    /*机构-停用*/
    function admin_stop(obj,id){
        layer.confirm('确认要未读吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            var url = SCOPE.status_url;
            $.post(url,{status:0,id:id},function(data){
                if(data.code == 1001){
                    layer.msg('未读!',{icon: 1,time:1000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon: 2,time:1000});
                }

            });


        });
    }

    /*机构-启用*/
    function admin_start(obj,id){
        layer.confirm('确认要已读吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……

            var url = SCOPE.status_url;
            $.post(url,{status:1,id:id},function(data){
                if(data.code == 1001){

                    layer.msg('已读!',{icon: 1,time:1000},function(){
                        window.location.reload();
                    });
                }else if(data.code == 399){
                    layer.confirm(data.msg,function(index){
                        //此处请求后台程序，下方是成功后的前台处理……

                        var url = SCOPE.merstatus;
                        $.post(url,{status:1,id:id},function(data){
                            if(data.code == 1001){

                                layer.msg('已读!',{icon: 1,time:1000},function(){
                                    window.location.reload();
                                });
                            }else{
                                layer.msg(data.msg,{icon: 2,time:1000});
                            }
                        });
                    });
                }else{
                    layer.msg(data.msg,{icon: 2,time:1000});
                }
            });
        });
    }


    laydate.render({
        elem: '#times'
        ,type: 'datetime'
        ,range: true
    });




</script>

<script src="__STATIC__/layui/xm-select.js"></script>
<script>
    var aData= JSON.parse('{$adminList}')
    var demo1 = xmSelect.render({
        el: '#demo1',
        filterable: true,
        name: 'admin_id',
        layVerify: 'required',
        language: 'zn',
        toolbar: {
            show: true,
            list: [ 'ALL', 'CLEAR', 'REVERSE' ]
        },
        data: aData
    })

</script>

</html>




























